﻿@using Cxuu.Common
@model IEnumerable<ViewCacheModel>


@{
    ViewData["Title"] = "操作日志";
}

<div class="content-top-nav">
    <div class="layui-row">
        <div class="layui-col-md11">
            <h3 style="color:#444">
                <i class="layui-icon layui-icon-home"></i>
                @ViewData["Title"]
            </h3>
        </div>
        <div class="layui-col-md1" style="text-align:right;">

        </div>
    </div>
    <hr>
</div>

<div class="layui-fluid" style="margin-bottom:50px;">
    <script type="text/html" id="toolbarAE">
        <div class="layui-btn-container">
            @if (CheckExt.AuthView(ViewBag.sr, "attment_addoredit"))
            {
                <button class="layui-btn layui-btn-sm data-add-btn">上传新文件</button>
            }
        </div>
    </script>

    <table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter"></table>

    <script type="text/html" id="UserTpl">
        {{d.username}} ({{d.userId}})
    </script>

     <script type="text/html" id="ImgTpl">
        {{# if(d.ext ==".jpg" ){ }}
             <img src="{{d.url}}">
        {{# }else{ }}
            {{d.url}}
        {{#  } }}
    </script>

    <script type="text/html" id="currentTableBar">
        @if (CheckExt.AuthView(ViewBag.sr, "attment_delete"))
        {
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        }
    </script>

</div>

<script>
    layui.use(['table', 'jquery', 'form'], function () {
        var table = layui.table, $ = layui.jquery, form = layui.form;

        form.render();

        table.render({
            elem: '#currentTableId',
            url: '/Admin/Attment/Index?json=1',
            toolbar: '#toolbarAE',
            cols: [[
                { field: 'id', title: 'Id', width:80 },
                { field: 'filename', title: '文件名' },
                { field: 'ext', title: '文件类型', width: 120, sort: true },
                { field: 'url', title: '位置',width:360 ,templet: '#ImgTpl'},
                { field: 'size', title: '大小(KB)', width: 120,sort: true },
                { field: 'source', title: '上传位置' },
                { field: 'username', title: '上传用户(ID)' ,templet: '#UserTpl'},
                { field: 'time', title: '上传时间'},
                { title: '操作', width: 160, templet: '#currentTableBar', fixed: "right", align: "center" }
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 20,
            id: 'tableReload',
            page: true
        });

        // 监听添加操作
        $(".data-add-btn").on("click", function () {
            loadMain('/Admin/Attment/AddOrEdit');
            return false;
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定删除' + data.id + '附件吗？', {
                    btn: ['确定', '取消']
                }, function (index) {
                    $.post('/Admin/Attment/Delete?id=' + data.id, function (res) {
                        if (res.status == 1) {
                            layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                obj.del();
                                layer.close(index);
                            });
                        } else {
                            layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                        }
                    });
                });
            }
        });




    });
</script>
